package org.cuijq.thinking.in.spring.dependency.lookup;

import javax.annotation.PostConstruct;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author by CuiJQ
 * @Classname BeanCreationExceptionDemo
 * @Description BeanCreationExceptionDemo Description
 * @Date 2021/6/28 20:23
 */
public class BeanCreationExceptionDemo {
  public static void main(String[] args) {
    AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(POJO.class);
    ac.registerBeanDefinition("errorBean",beanDefinitionBuilder.getBeanDefinition());
    ac.refresh();
    ac.close();
  }
  static class POJO implements InitializingBean{

    //CommonAnnotationBeanPostProcessor
    @PostConstruct
    public void init()throws Throwable{
      throw  new Exception("init():For purpoess");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
      throw  new Exception("For purpoess");
    }
  }
}
